{%extend name="Public:layout"/%}

{%block name="title"%}
<h2 class="mb20">
    资讯管理
</h2>
{%/block%}

{%block name="contents"%}
<div class="heading clearfix">
    <div class="pull-right">
        <a href="{%:U('/admin/news/save/')%}" class="btn mr5"><i class="icon i-add"></i>发布资讯</a>
    </div>
</div>
<table class="table table-hovered">
    <thead class="thead-gray">
    <tr>
        <th>资讯日期</th>
        <th>排序</th>
        <th>资讯标题</th>
        <th>图片</th>
        <th>状态</th>
        <th>资讯ID</th>
        <th>APP内浏览量</th>
        <th>点赞</th>
        <th>评论</th>
        <th>管理</th>
    </tr>
    </thead>
    <tbody>
    {%notempty name="list"%}
    {%foreach name="list" item="vo"%}
    {%neq name="temp" value="$vo['date_ymd']"%}
    <tr><td colspan="10" style="height: 2px; background-color: #78A6DD; padding: 0;"></td></tr>
    {%/neq%}
    {%php%}$temp = $vo['date_ymd'];{%/php%}
    <tr>
        <td>{%$vo.date_ymd%}</td>
        <td><input type="text" size="3" name="order_{%$vo.news_id%}" value="{%$vo.order_by%}" onblur="ST.todo('changeOrder', '{%$vo.news_id%}')" /></td>
        <td>{%$vo.news_title%}</td>
        <td><img width="100" height="50" src="{%$vo.news_img|httpThumb=0,100%}" /></td>
        <td>
            {%eq name="vo['status']" value="1"%}
            <font color="green">已上线</font>
            <a href="javascript:;" onclick="ST.todo('publish', '{%$vo.news_id%}')">下线</a>
            {%else/%}
            待上线
            <a href="javascript:;" onclick="ST.todo('publish', '{%$vo.news_id%}')">上线</a>
            {%gt name="vo['auto_publish_time']" value="0"%}
            <br/><font color="red">自动上线：{%$vo['auto_publish_time']|date='Y-m-d H:i',###%}</font>
            {%/gt%}
            {%/eq%}
        </td>
        <td>{%$vo.news_id%}</td>
        <td><a href="{%:U('/admin/statisticview/getlist/')%}?type=2&id={%$vo.news_id%}">{%$vo.views%}</a></td>
        <td><a href="{%:U('/admin/statisticpraise/getlist/')%}?type=2&id={%$vo.news_id%}">{%$vo.praises%}</a></td>
        <td><a href="{%:U('/admin/statisticcomment/getlist/')%}?type=2&id={%$vo.news_id%}">{%$vo.commentCount%}</a></td>
        <td>
            <a href="{%:U('/admin/news/save/')%}?news_id={%$vo.news_id%}"><i class="icon i-edit"></i></a>
            <a href="javascript:;" onclick="ST.todo('del','{%$vo.news_id%}')"><i class="icon i-del"></i></a>
            
            
            <a href="{%:U('/admin/comment/getlist')%}?type=2&id={%$vo.news_id%}">评论记录</a>
            <a target="_blank" href="{%:U('/admin/public/preview/')%}?news_id={%$vo.news_id|num_encode%}"><i class="icon i-arrow-right"></i>预览</a>
            <a href="javascript:;" onclick="ST.todo('push','{%$vo.news_id%}','1')"><i class="icon i-arrow-right"></i>推送</a>
        </td>
    </tr>
    {%/foreach%}
    {%/notempty%}
    </tbody>
</table>
<h2 class="m20"></h2>
<div class="paging">{%$page%}</div>
{%/block%}

{%block name="js"%}
<script src="__JAVASCRIPT__/ST.Calender.js"></script>
<script>
    $.extend(ST.ACTION, {
        'change_order': "{%:U('/admin/news/change_order')%}",
        'publish': "{%:U('/admin/news/publish')%}",//删除目录action地址
        'del': "{%:U('/admin/news/del')%}",//删除目录action地址
        'save': "{%:U('/admin/news/save')%}",//添加目录弹窗地址
        'push': "{%:U('/admin/push/broadcast')%}"//推送内容
    });
    $.extend(ST, {
        changeOrder: function(id) {
            ST.execAJAX({
                url: ST.ACTION.change_order,     //服务端请求地址
                params: {news_id: id, order_by: $('input[name=order_' + id +']').val()},
                hasconfirm: false,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                }
            });
        },
        save: function (id) {
            ST.editBox(ST.ACTION.save + '/news_id/' + id, {
                title: id == 0 ? '添加' : '修改',
                width: 960,
                height: '100%'
            });
        },
        publish: function (id) {
            ST.execAJAX({
                url: ST.ACTION.publish,     //服务端请求地址
                params: {news_id: id},       //发送到服务端的参数（如：{myparam:1}）
                hasconfirm: false,
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        },
        del: function (id) {
            ST.execAJAX({
                url: ST.ACTION.del,     //服务端请求地址
                params: {news_id: id},       //发送到服务端的参数（如：{myparam:1}）
                massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
                hasconfirm: true,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        },
        //批量删除
        delAll: function () {
            var ids = ST.getSelectedValue().join(',');
            if (!ids) {
                ST.tipMsg('请至少选择一项');
            } else {
                ST.del(ids);
            }
        },
        //获得选中值
        getSelectedValue: function () {
            var $options = $('.js-toggleall-target:checked'), arr = [];
            $options.each(function () {
                arr.push($(this).val());
            });
            return arr;
        },
        push: function (about_id, type) {
            ST.execConfirmAJAX({
                url: ST.ACTION.push,     //服务端请求地址
                params: {about_id: about_id, type: type},       //发送到服务端的参数（如：{myparam:1}）
                title: '请选择编辑',
                massage: ST.JTE.fetch('news_push_tpl').getFilled({
                    auto_publish_hours: {%$auto_publish_hours|json_encode%}
                }),
                attachParamsFun: function(){
                	var editor = $("input[name='editor']:checked");
                	console.log(editor);
                	if(editor.length > 0){
                		var name = editor.val();
                		var avator = editor.parent().find("img").attr("src");
                		var is_crontab = $("input[name='is_crontab']:checked").val();
                        var auto_publish_hour = $("select[name='auto_publish_hour']").val();
                        var auto_publish_time = $("input[name='auto_publish_time']").val();
                		return {editor_name:name, editor_avator:avator, is_crontab:is_crontab, auto_publish_time:auto_publish_time, auto_publish_hour:auto_publish_hour};
                	}
                },       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                	if (!j) return;
                }
            });
            var this_year = new Date().getFullYear();
            var _auto_calender = new ST.Calender("_auto_calender", "", this_year, this_year);
        }
    });
    ST.init();
</script>
{%/block%}